package com.one;

import java.text.SimpleDateFormat;
import java.util.*;
import java.text.DateFormat;
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.*;
import javax.mail.internet.*;

public class Mail {
 static int addtime = 9;
static String currentdate;
static String currentFileDate;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
		Calendar currentcal = Calendar.getInstance();
		if (addtime< 1){
			addtime = -1 * addtime;
		}
		currentcal.add(Calendar.DAY_OF_MONTH,-1);
		currentdate =  new SimpleDateFormat("dd-MMM-yyyy").format(currentcal.getTime()).toUpperCase(); 
		currentFileDate =  new SimpleDateFormat("yyyyMMdd").format(currentcal.getTime()).toUpperCase(); 
		
		System.out.println(dateFormat.format (currentcal.getTime()).toUpperCase());
		System.out.println(currentFileDate);
		System.out.println(currentdate);
		
		String to = "7millionatives@gmail.com";
        String from = "7millionatives@gmail.com";

        Properties properties = System.getProperties();
        properties.setProperty("mail.smtp.host", "smpt.gmail.com");
       // properties.put("mail.smtp.auth", "true");
        Session session = Session.getDefaultInstance(properties, null);
        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

            message.setSubject("Phone Home: ET");
            message.setText("If you are seeing this, then its OK");
            
            Transport.send(message);
            
            System.out.println("Sent message successfully....");
            
        } catch (MessagingException em) {
            
            System.out.println(em.getMessage());
        }
	}
	

}
